const express = require('express'),
    db = require('./db'),
    router = express.Router();

//添加数据
router.post('/create', (req, res) => {
    let SuccessMessage = '添加编辑成功',
        FailMessage = '添加数据失败';
    db.post(req, SuccessMessage, FailMessage, res)

})

//删除数据
router.delete('/delete/:id', (req, res) => {
    let SuccessMessage = '删除编辑成功',
        FailMessage = '删除数据失败';
    db.delete(req, SuccessMessage, FailMessage, res)
});

//修改数据
router.put('/:id/edit', (req, resp) => {
    let id = req.params.id,
        SuccessMessage = '修改数据成功',
        FailMessage = '修改数据失败';
    db.put(id, SuccessMessage, FailMessage, req, resp)
});
//获取编辑数据
router.get('/getDeitData/:id', (req, resp) => {
    let id = req.params.id,
        sql = 'SELECT * FROM listarticle WHERE id=?',
        SuccessMessage = '获取数据编辑成功',
        FailMessage = '获取编辑数据失败',
        data = [id];
    db.get(resp, SuccessMessage, FailMessage, sql, data)
});

//获取数据
router.get('/list', (req, resp) => {
    let sql = 'SELECT * FROM listArticle',
        SuccessMessage = '获取数据成功',
        FailMessage = '获取数据失败',
        data = [];
    db.get(resp, SuccessMessage, FailMessage, sql, data)
});

module.exports = router;